package kadledav.hook;

import kadledav.backend.dto.NewsDTO;

import org.apache.log4j.Logger;

import com.liferay.portal.ModelListenerException;
import com.liferay.portal.model.BaseModelListener;
import com.liferay.portal.model.User;

public class ModelListener extends BaseModelListener<User> {
	private static final Logger logger = Logger.getLogger(ModelListener.class);

	@Override
	public void onAfterCreate(User user) throws ModelListenerException {
		super.onAfterCreate(user);
		NewsDTO newOne = new NewsDTO();
		String msg = HookResourceHolder.resource.getString("userCreated");
		newOne.setMessage(msg.replace("${screenName}", user.getScreenName()).replace("${email}", user.getEmailAddress()));
		logger.info("new message: " + newOne.getMessage());
		ServiceContainer.newsService.addNews(newOne);
	}
}
